package com.league.zjxn.main.access

import android.widget.TextView
import androidx.core.widget.addTextChangedListener
import com.league.zjxn.R
import com.league.zjxn.jetpack.vmodel.AccessViewModel
import com.module.lemlin.http.Status
import com.module.lemlin.owner.OwnerViewModeFragment
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Flowable
import kotlinx.android.synthetic.main.fragment_access_login_code.*
import java.util.concurrent.TimeUnit

class LoginCodeFragment : OwnerViewModeFragment<AccessViewModel>() {

    companion object {
        fun newInstance(): LoginCodeFragment {
            return LoginCodeFragment()
        }
    }

    override fun viewModel(): AccessViewModel {
        return createViewModel(requireActivity())
    }

    override val layoutResId: Int
        get() = R.layout.fragment_access_login_code

    override fun initView() {

        etLoginCodePhone.addTextChangedListener { editable ->
            editable?.let { viewModel.mMapLoginCode["mobile"] = it.toString() }
            tvLoginCodeSubmit.isEnabled =
                !editable.isNullOrEmpty() && !etLoginCodeCode.text.isNullOrEmpty()
        }
        etLoginCodeCode.addTextChangedListener { editable ->
            editable?.let { viewModel.mMapLoginCode["code"] = it.toString() }
            tvLoginCodeSubmit.isEnabled =
                !editable.isNullOrEmpty() && !etLoginCodePhone.text.isNullOrEmpty()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        viewModel.mMapLoginCode.clear()
    }
}